﻿@model StackExchange.DataExplorer.ViewModel.QueryViewerData
@using StackExchange.DataExplorer
@using StackExchange.DataExplorer.Models
@{
    Layout = "~/Views/Shared/Query.cshtml";
    this.SetPageTitle(Model.Revision.QuerySet.Title + " - Stack Exchange Data Explorer");

    var querySet = Model.Revision.QuerySet;
    var initialRevision = querySet.InitialRevision;
    var currentRevision = Model.Revision;
}

@section Metadata
{
    @Html.Partial("QueryVoting", Model.QuerySetVoting)
    <p class='description'>@Model.Revision.QuerySet.Description</p>
}

@helper UserSignature(User user, DateTime date, bool isEdit, bool isOwner)
{
<div class="user-info@(isOwner && !isEdit?" owner":"")">
    <div class="user-action-time">@(isEdit?"edited":"created") @date.ToRelativeTimeSpanMicro()</div>
    @if ((isOwner && !isEdit) || !isOwner)
    { 
        <div class="user-gravatar32"><a href="/users/@user.Id">@Html.Raw(user.Gravatar(32))</a>
            @if (user.IsAnonymous == null)
            { 
                <span>anonymous</span>
            }
            else
            { 
                <a href="/users/@user.Id">@user.Login</a>
            }
        </div>
    }
</div>
}

<pre id="queryBodyText" class="cm-s-default"><code>@Model.Revision.Query.QueryBody</code></pre>

<table class="fw">
    <tbody><tr>
    <td class="vt">
        <div class="toolbar">
            @if (querySet.CurrentRevisionId != Model.Revision.Id)
            {
                  <a href="/@Current.Controller.Site.Name.ToLower()/query/@querySet.Id@querySet.Slugify()">view current version</a>
            }
            else
            {
                if (querySet.OwnerId == Current.User.Id)
                { 
                <a href="/@Current.Controller.Site.Name.ToLower()/query/edit/@querySet.Id">edit query</a>
                }
                else
                { 
                <a href="/@Current.Controller.Site.Name.ToLower()/query/fork/@querySet.Id">fork query</a>
                }
            }
        </div>
       
    </td>
    <td class="post-signature">  
        @if (querySet.InitialRevisionId != querySet.CurrentRevisionId)
        { 
            @UserSignature(currentRevision.Owner, currentRevision.CreationDate, isEdit: true, isOwner: (initialRevision.OwnerId == currentRevision.OwnerId));
        }
    </td>
    <td class="post-signature">
         @UserSignature(initialRevision.Owner, initialRevision.CreationDate, isEdit: false, isOwner: true)
    </td>
    </tr>
    </tbody>
</table>



